﻿import Cookies from 'js-cookie'
export default function preSignature(url,num,Request,xb) {
	function suc(){
		$.ajax({
			type: "post",
			url: Request + '/sharing.do',
			data: { 'phoneNum': localStorage.getItem('caiquanMobile10086'),sharingStatus:'1' },
			dataType: "json",
			success: data => {
					if (data.resCode == 0) {
							$('.heart i').css({ "background": "url(" + num[data.retMsg.physicalValue] + ")", 'backgroundSize': '100% 100%' })
							$('.prize').css({ "background": "url(" + xb[data.retMsg.beishu-1] + ")", 'backgroundSize': '100% 100%' })
							Cookies.set('health',data.retMsg.physicalValue)
						} 
					  $('.comText').show()
            $('#comText').text(data.resultString)
			}
		});
	}

	$.ajax({
	  type: "GET",
		url:"https://www.shandong10086.com/tiger/commonCtl/getSignature?url=" +encodeURIComponent(location.href.split('#')[0]),
	  dataType: "json",
	  async: false,
	  success: function(data) {
		let Signature =  JSON.parse(data.data);
		wx.config({
		  debug: false,
			appId:"wx43a850f87498127d",
			timestamp: Signature.timeStamp,
			nonceStr: Signature.nonceStr,
			signature:Signature.jsSignature,
			jsApiList: [
				'onMenuShareTimeline',
				'onMenuShareAppMessage',
				'hideMenuItems'
			]
		});
		wx.ready(function() {
		  wx.onMenuShareTimeline({
			title: "您有一份奖励待领取~", // 分享标题
			link: url, // 分享链接
			imgUrl:"https://wx.online-cmcc.cn/shandong/wx/otherSamllProject/shareIcon/shareFight.png",
			success: function() {
					setTimeout(() => {
						suc()
					}, 500);
			},
			cancel: function() {
			  // 用户取消分享后执行的回调函数
			}
		  });
  
		  wx.onMenuShareAppMessage({
			title: "您有一份奖励待领取~", // 分享标题
			desc:
			  "猜拳赢双重大奖，手机、观影券等你来拿~", // 分享描述
			link: url,
			imgUrl:"https://wx.online-cmcc.cn/shandong/wx/otherSamllProject/shareIcon/wx_sign.png",
			success: function() {
				setTimeout(() => {
					suc()
				}, 500);
			},
			cancel: function() {
			  // 用户取消分享后执行的回调函数
			}
		  });
		});
		// wx.error(function (res) {
		// 	alert(res.errMsg);
		//  });
	  }
	});
  }
  